public class Test {
    //
}

//自己实现一个阻塞队列 ~ ~
class MyBlockingQueue {
    //属性
    //创建一个锁对象
    Object lock = new Object();
    //创建一个队列
    String[] strs = new String[5];
    int head = 0;
    int tail = 0;//指向可用位置
    int size = 0;//队里中有效元素个数
    int len = strs.length;



    //入队列，put方法
    void put(String s) throws InterruptedException {
        synchronized (lock){
            //……阻塞
            while(size >= len){
                lock.wait();
            }
            //入队列
            strs[tail] = s;
            tail++;
            if(tail >= len-1){//我怎么感觉，这里可以=，=的时候，tail指向的位置也是可以放的？？？
                tail = 0;
            }
            size++;//别忘了：更新size
            lock.notify();
        }
    }

    /*synchronized (lock){
        //
        String get() throws InterruptedException {
            while(size <= 0){
                lock.wait();
            }

            String s = strs[head];
            head ++;
            size --;
            if(head >= len-1){
                head = 0;
            }
            lock.notify();
            return s;
        }
    }*/
    String get() throws InterruptedException {
        synchronized (lock){
            while(size <= 0){
                lock.wait();
            }

            String s = strs[head];
            head ++;
            size --;
            if(head >= len-1){
                head = 0;
            }
            lock.notify();
            return s;
        }
    }


}
